<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="button" value="开始" onClick="timedCount()">
    <input type="button" value="结束" onClick="timedOver()">
    <p id="timeShow">00:00:00</p>

    <script type="text/javascript">
        var minuteVal=0;
        var timeVal;
        //开始计时
        function timedCount(){
            minuteVal=minuteVal+1;
            var timeResult=formatSeconds(minuteVal);
            document.getElementById('timeShow').innerHTML=timeResult;
            timeVal=setTimeout("timedCount()",1000); 
        }
        //结束计时
        function timedOver(){
            clearTimeout(timeVal);
        }

        //秒转化为时分秒
        function formatSeconds(value) {
            var secondTime = parseInt(value);// 秒
            var minuteTime = 0;// 分
            var hourTime = 0;// 小时
            if(secondTime > 59) {//如果秒数大于60，将秒数转换成整数
                //获取分钟，除以60取整数，得到整数分钟
                minuteTime = parseInt(secondTime / 60);
                //获取秒数，秒数取佘，得到整数秒数
                secondTime = parseInt(secondTime % 60);
                //如果分钟大于60，将分钟转换成小时
                if(minuteTime > 59) {
                    //获取小时，获取分钟除以60，得到整数小时
                    hourTime = parseInt(minuteTime / 60);
                    //获取小时后取佘的分，获取分钟除以60取佘的分
                    minuteTime = parseInt(minuteTime % 60);
                }
            }
            var result = "00:00:" + less(parseInt(secondTime));

            if(minuteTime > 0) {
                result = "00:" + less(parseInt(minuteTime)) + ":" + less(parseInt(secondTime));
            }
            if(hourTime > 0) {
                result = less(parseInt(hourTime))+":"+less(parseInt(minuteTime))+":"+less(parseInt(secondTime));
            }
            return result;
        }

        //小于10为01
        function less(val){
          if(val<10){
             return "0"+val;
          }
          return val;
        }
    </script>
</body>
</html>